10 ' maxitnew.bas - FREEWARE 2004
20 GOTO 150 ' begin
30 SAVE "maxitnew":LIST-150
40 GOTO 210 ' initialize
50 GOTO 260 ' wait for key
60 GOTO 580 ' player 1
70 GOTO 610 ' player 2
80 GOTO 640 ' choose player
90 GOTO 790 ' score it
100 GOTO 820 ' computer selects
110 GOTO 1010 ' info
120 GOTO 1210 ' print@ 2 locate
130 GOTO 1250 ' get key
140 ' begin
150 CLS:SCREEN 9:KEY OFF:DIM BD$(7,7)
160 OH=100:MH=-100:A3=0:A2=0:PW=0:SV=0:MY=0:PQ=0:GG=0:MT=0:MX=0
170 DT=0:PC=0:PK=0:A1=0:C2=0:Z=0:O=1                   ' locals
180 DIM AV(64):SZ=7:NQ=64:DEFSTR Q:Q=MKI$(0)
190 RANDOMIZE TIMER:GOTO 280
200 ' initialize
210 PC$=BD$(I,J):PP=150+128*I+4*J:V=PP  :GOSUB 120:PRINT "";
220 IF MD=2 THEN PRINT CHR$(221) :V=PP+3:GOSUB 120:PRINT CHR$(222)
230 IF VAL(PC$)=OH THEN V=PP:GOSUB 120:PRINT MM$:C1=I:C2=J:RETURN
240 IF VAL(PC$)=MH THEN V=PP:GOSUB 120:PRINT "    ";:RETURN
250 V=PP+1:GOSUB 120:PRINT PC$;:IF MD=2 THEN RETURN ELSE V=PP:GOSUB 120:PRINT " "PC$" ";:RETURN
260 GOSUB 130:RETURN
270 ' build cursor
280 MM$=CHR$(222)+CHR$(223)+CHR$(223)+CHR$(221)
290 GOSUB 110 ' info
300 CLS:LOCATE 4,4:PRINT MM$:LOCATE 4,9:PRINT "One or two players (1-2) ? ";
310 GOSUB 50:NP=VAL(Q):PRINT Q:IF NP=2 THEN 350
320 P2$="Computer"
330 INPUT "          Enter your name please ";P1$
340 GOTO 370
350 INPUT "                Name of player 1 ";P1$
360 INPUT "                Name of player 2 ";P2$
370 CLS:COLOR 15,0
380 FOR I=170 TO 440:PSET(I,15):PSET(I,250):NEXT ' draw horizontal lines
390 FOR I=15 TO 250:PSET(170,I):PSET(440,I):NEXT ' draw vertical lines
400 IF LEN(P1$)>12 THEN  P1$=LEFT$(P1$,12)
410 IF LEN(P2$)>12 THEN  P2$=LEFT$(P2$,12)
420 MD=1:FOR K=1 TO NQ:AV(K)=K:NEXT
430 FOR K=NQ TO 1 STEP -1
440  READ PC$:P1=O+INT(RND(1)*K):J=AV(P1)-O
450  IF P1<K THEN FOR A3=P1 TO K-O:AV(A3)=AV(A3+O):NEXT
460  I=INT(J/(SZ+O)):J=J-(SZ+O)*I:BD$(I,J)=PC$:GOSUB 40
470 NEXT:RESTORE
480 S1=0:S2=0:GOSUB 90
490 PL=1:GOSUB 60:IF FL=0 THEN 500 ELSE PL=2:GOSUB 70:IF FL<>0 THEN 490
500 LOCATE 21,1:PRINT CHR$(4)" ";:ON 2+SGN(S2-S1) GOSUB 540,550,560
510 LOCATE 22,1:PRINT CHR$(3)" Would you like to play again <y/n> ";
520 GOSUB 130:IF ASC(Q)=121 OR ASC(Q)=89 THEN 370 ' y Y
530 GOTO 1300
540 LOCATE 21,1:PRINT P1$" has won with "S1-S2"points.";:RETURN
550 LOCATE 21,1:PRINT    " It's a draw                ";:RETURN
560 LOCATE 21,1:PRINT P2$" has won with "S2-S1"points.";:RETURN
570 ' player 1
580 FL=600:FOR J=0 TO SZ:FL=FL+VAL(BD$(C1,J)):NEXT
590 IF FL=0 THEN RETURN ELSE NM$=P1$:DX=1:DY=0:GOSUB 80:RETURN
600 ' player 2
610 FL=600:FOR I=0 TO SZ:FL=FL+VAL(BD$(I,C2)):NEXT
620 IF FL=0 THEN RETURN ELSE NM$=P2$:DX=0:DY=1:GOSUB 80:RETURN
630 ' choose player
640 Y=C1:X=C2:FX=1:IF NP=2 OR PL=1 THEN 670
650 LOCATE 20,1:PRINT CHR$(4)" "NM$" to play                 "
660 GOSUB 100:GOTO 740
670 LOCATE 20,1:PRINT CHR$(3)" "NM$" to play                 "
680 GOSUB 50:IF ASC(Q)<>32 THEN 730 ELSE OX=X:OY=Y
690 Y=Y+DY:IF Y>SZ THEN Y=0
700 X=X+DX:IF X>SZ THEN X=0
710 PT=VAL(BD$(Y,X)):IF ABS(PT)=100 THEN 690
720 MD=1:I=OY:J=OX:GOSUB 40:MD=2:I=Y:J=X:GOSUB 40
730 IF ASC(Q)<>13 THEN 670 ELSE IF ABS(VAL(BD$(Y,X)))=100 THEN 670
740 MD=1:I=C1:J=C2:BD$(I,J)="-100":GOSUB 40:I=Y:J=X
750 PT=VAL (BD$(I,J)):BD$(I,J)="100":GOSUB 40:S1=S1-(PL=1)*PT
760 S2=S2-(PL=2)*PT
770 COLOR 15,0:LOCATE 7,3:PRINT "Last":LOCATE 8,3:PRINT "in MAXIT "PT
780 ' score it
790 COLOR 12,0:LOCATE 3,1 :PRINT CHR$(3)" "P1$:LOCATE 4,3 :PRINT "Score "S1:COLOR 15,0
800 COLOR 14,0:LOCATE 11,1:PRINT CHR$(4)" "P2$:LOCATE 12,3:PRINT "Score "S2:COLOR 15,0:RETURN
810 ' computer selects a number
820 MT=MH:GG=-1
830 FOR A1=Z TO SZ
840  PC=VAL(BD$(A1,C2)):IF ABS(PC)=OH THEN 990
850  MX=MH
860  FOR A2=Z TO SZ
870   IF A2<>C2 THEN PK=VAL(BD$(A1,A2)) ELSE GOTO 890
880   IF PK<>MH AND PK>MX THEN MX=PK:SV=A2
890  NEXT:IF MX<>MH THEN 900 ELSE IF PC>MT THEN MT=PC:GG=A1:GOTO 990
900  IF GG<Z THEN GG=A1
910  FOR A2=Z TO SZ
920   PQ=VAL(BD$(A2,SV)):IF PQ=MH OR A2=A1 THEN 980
930   MY=MH
940   FOR A3=Z TO SZ:PW=VAL(BD$(A2,A3)):IF A3=SV THEN 960
950    IF ABS(PW)<>OH AND PW>MY THEN MY=PW
960   NEXT:IF MY=MH THEN MY=Z
970   DT=PC-MX+PQ-MY:IF DT>MT THEN MT=DT:GG=A1
980  NEXT
990 NEXT:Y=GG:RETURN
1000 ' info
1010 CLS:LOCATE 2,3:PRINT MM$
1020 LOCATE 2,8:PRINT "The object of MAXIT is to get as many points"
1030 LOCATE 3,8:PRINT "              as possible."
1040 LOCATE 5,8:PRINT "  Two players can play against each other,"
1050 LOCATE 6,8:PRINT "       or one against the COMPUTER."
1060 LOCATE 8,8:PRINT "   You get points by moving the cursor to"
1070 LOCATE 9,8:PRINT "       a space with a number in it."
1080 LOCATE 10,8: PRINT "The first player always moves horizontally,"
1090 LOCATE 11,8:PRINT "  and the second player moves vertically."
1100 LOCATE 13,8:PRINT "You indicate the place you want to move to"
1110 LOCATE 14,8:PRINT "by using the spacebar to position yourself."
1120 LOCATE 16,8:PRINT "  Push the <Enter> key to take that piece."
1130 LOCATE 17,8:PRINT "      <Esc> always exits immediately."
1140 LOCATE 19,8:PRINT "     Press any key to start the game."
1150 GOSUB 50:RETURN
1160 DATA 15,10,09,09,08,08,07,07,07,06,06,06,05,05,05,05,04,04
1170 DATA 04,04,03,03,03,03,03,02,02,02,02,02,02,01,01,01,01,01
1180 DATA 00,00,00,00,00,00,-1,-1,-1,-1,-1,-2,-2,-2,-2,-3,-3,-3
1190 DATA -4,-4,-4,-5,-5,-6,-6,-7,-9,100
1200 ' print @ to locate converter
1210 EQ=INT(V/64)+1:A=(V-(EQ-1)*64)+1:LOCATE EQ,A
1220 IF VAL(PC$)>0 THEN COLOR 11,0 ELSE COLOR 15,0
1230 RETURN
1240 ' get key
1250 LSET Q=MKI$(0)
1260 WHILE CVI(Q)=0:MID$(Q,1)=INKEY$:WEND
1270 IF ASC(Q)=27 THEN 1300
1280 RETURN
1290 ' exit
1300 CLS:SCREEN 0
1310 KEY 5,"maxitnew.bas":KEY 6,CHR$(34)+",a":KEY ON
